﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package zasp.Display {
    import flash.events.*;
    import flash.display.*;
    import zasp.Util.*;

    public class FunkySpinner extends Sprite implements Sampler {

        private static const PHI:Number = ((1 + Math.sqrt(5)) / 2);
        private static const goldenSpiralC:Number = (1 / Math.pow(PHI, 4));
        private static const silverSpiralC:Number = (1 / Math.pow(PHI, 2));
        private static const copperSpiralC:Number = (1 / PHI);
        private static const C:Number = silverSpiralC;
        private static const millisPerCycle:Number = 2000;
        private static const slicesPerCycle:int = 60;
        private static const totalNumSlices:int = 150;
        private static const colors:Array = [0, 0xFF0000, 0xFF00, 0xFF, 0x7F7F7F, 16744319, 8388479, 8355839, 0xBFBFBF, 16760767, 12582847, 12566527, 0xDFDFDF, 16768991, 14680031, 14671871, 0xFFFFFF];

        private var slices:Array;
        private var samplesMillis:CircularBuffer = null;

        public function FunkySpinner(_arg1:Number, _arg2:Number, _arg3:Number){
            var _local5:ColorPoly;
            var _local6:Number;
            var _local7:Number;
            var _local8:Number;
            var _local9:Number;
            var _local10:Number;
            var _local11:Number;
            var _local12:Number;
            var _local13:Number;
            var _local14:Number;
            var _local15:Number;
            var _local16:Number;
            var _local17:Number;
            var _local18:Number;
            var _local19:Number;
            var _local20:Number;
            var _local21:Number;
            var _local22:Number;
            var _local23:Number;
            var _local24:Number;
            this.slices = new Array();
            super();
            this.samplesMillis = new CircularBuffer((colors.length - 1));
            var _local4:int;
            while (_local4 < totalNumSlices) {
                _local5 = new ColorPoly();
                this.slices.push(_local5);
                addChild(_local5);
                _local6 = Math.PI;
                _local7 = ((((2 * _local6) * (_local4 + 0)) / slicesPerCycle) - (_local6 / 2));
                _local8 = ((((2 * _local6) * (_local4 + 1)) / slicesPerCycle) - (_local6 / 2));
                _local9 = Math.cos(_local7);
                _local10 = Math.sin(_local7);
                _local11 = Math.cos(_local8);
                _local12 = Math.sin(_local8);
                _local13 = (_arg3 * Math.pow(C, ((_local4 + 0) / slicesPerCycle)));
                _local14 = (_local13 * C);
                _local15 = (_arg3 * Math.pow(C, ((_local4 + 1) / slicesPerCycle)));
                _local16 = (_local15 * C);
                _local17 = (_arg1 + (_local13 * _local9));
                _local18 = (_arg2 + (_local13 * _local10));
                _local19 = (_arg1 + (_local14 * _local9));
                _local20 = (_arg2 + (_local14 * _local10));
                _local21 = (_arg1 + (_local15 * _local11));
                _local22 = (_arg2 + (_local15 * _local12));
                _local23 = (_arg1 + (_local16 * _local11));
                _local24 = (_arg2 + (_local16 * _local12));
                _local5.addPt(_local17, _local18);
                _local5.addPt(_local21, _local22);
                _local5.addPt(_local23, _local24);
                _local5.addPt(_local19, _local20);
                _local5.addPt(_local17, _local18);
                _local4++;
            };
            this.addListener(Event.ADDED_TO_STAGE, this.added_to_stage);
        }
        public function sample(_arg1:Number):void{
            while (this.samplesMillis.length >= (this.samplesMillis.capacity - 1)) {
                this.samplesMillis.pop();
            };
            this.samplesMillis.push(_arg1);
        }
        private function addListener(_arg1:String, _arg2:Function):void{
            addEventListener(_arg1, _arg2, false, 0, true);
        }
        private function removeListener(_arg1:String, _arg2:Function):void{
            removeEventListener(_arg1, _arg2, false);
        }
        private function added_to_stage(_arg1:Event):void{
            this.removeListener(Event.ADDED_TO_STAGE, this.added_to_stage);
            this.addListener(Event.ENTER_FRAME, this.enter_frame);
            this.addListener(Event.REMOVED_FROM_STAGE, this.removed_from_stage);
        }
        private function removed_from_stage(_arg1:Event):void{
            this.addListener(Event.ADDED_TO_STAGE, this.added_to_stage);
            this.removeListener(Event.ENTER_FRAME, this.enter_frame);
            this.removeListener(Event.REMOVED_FROM_STAGE, this.removed_from_stage);
        }
        private function enter_frame(_arg1:Event):void{
            var _local8:ColorPoly;
            var _local2:Number = (millisPerCycle / slicesPerCycle);
            var _local3:int = Math.min(colors.length, this.samplesMillis.length);
            var _local4:int;
            var _local5:int;
            var _local6:Number = 0;
            var _local7:int;
            if (this.samplesMillis.length > 0){
                _local7 = (this.samplesMillis.length - 1);
                _local6 = (this.samplesMillis.elementAt(_local7) as Number);
            };
            while ((((_local5 < _local3)) && ((_local4 < totalNumSlices)))) {
                _local8 = (this.slices[_local4] as ColorPoly);
                _local8.changeColor(colors[_local5]);
                _local4++;
                while (((((_local2 * _local4) > _local6)) && ((_local5 < _local3)))) {
                    _local7 = ((this.samplesMillis.length - _local5) - 1);
                    _local6 = (_local6 + (this.samplesMillis.elementAt(_local7) as Number));
                    _local5++;
                };
            };
            while (_local4 < totalNumSlices) {
                _local8 = (this.slices[_local4] as ColorPoly);
                _local8.changeColor(colors[(colors.length - 1)]);
                _local4++;
            };
        }

    }
}//package zasp.Display 
